import { request } from '../../../services/request';
import { AsnTrayInStoreQueryParams, AsnTrayInStoreResponse } from './types';

export const queryAsnTrayInStore = async (params: AsnTrayInStoreQueryParams): Promise<AsnTrayInStoreResponse> => {
    console.log('请求参数:', params);

    try {
        const response = await request('app/wms/asn/queryInStoreAsn', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('接口返回:', response);
        return response;
    } catch (error) {
        console.error('查询 ASN 失败:', error);
        throw error;
    }
};

export const confirmAsnTrayInStore = async (params: { shelf_num: string; tray_num: string }): Promise<any> => {
    console.log('确认托盘入库请求参数:', params);

    try {
        const response = await request('/app/wms/asn/trayInStore', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('确认托盘入库接口返回:', response);
        return response;
    } catch (error) {
        console.error('确认托盘入库失败:', error);
        throw error;
    }
};

export const getBodyListByBusNum = async (tray_num: string): Promise<any> => {
    try {
        const response = await request('/app/wms/asn/getSuggestInStoreShelfNum', {
            method: 'POST',
            body: JSON.stringify({ tray_num }),
        });
        return response;
    } catch (error) {
        console.error('获取产品列表失败:', error);
        throw error;
    }
};

export const getProductSkuList = async (product_id: string): Promise<any> => {
    try {
        const response = await request('/app/appProduct/getProductSkuList', {
            method: 'POST',
            body: JSON.stringify({ product_id }),
        });
        return response;
    } catch (error) {
        console.error('获取SKU列表失败:', error);
        throw error;
    }
};

export const getSuggestInStoreShelfNum = async (product_id: string): Promise<any> => {
    try {
        const response = await request('/app/wms/asn/getSuggestInStoreShelfNum', {
            method: 'POST',
            body: JSON.stringify({ product_id }),
        });
        return response;
    } catch (error) {
        console.error('获取推荐储位失败:', error);
        throw error;
    }
};

export const getSuggestInStoreShelfNumByTray = async (tray_num: string): Promise<any> => {
    try {
        const response = await request('/app/wms/asn/getSuggestInStoreShelfNum', {
            method: 'POST',
            body: JSON.stringify({ tray_num }),
        });
        return response;
    } catch (error) {
        console.error('获取推荐储位失败:', error);
        throw error;
    }
};
